package com.suray.attendance.db.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.suray.attendance.model.pojo.DeptInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;

@Mapper
public interface DeptInfoMapper extends BaseMapper<DeptInfo> {


    @Insert("<script>" +
            "INSERT INTO ding_dept_info (id, pid, name ,create_time) VALUES " +
            "<foreach collection='list' item='item' separator=','>" +
            "(#{item.id}, #{item.pid}, #{item.name},#{item.createTime})" +
            "</foreach>" +
            "</script>")
    void batchInsert(@Param("list") List<DeptInfo> deptInfoList);

    @Select("SELECT id FROM ding_dept_info WHERE pid=#{pid};")
    List<Long> selectByPid(@Param("pid") Long pid);

    @Select("SELECT id FROM ding_dept_info")
    List<Long> selectAllIdList();

    @Select("<script>" +
            "SELECT pid,id FROM ding_dept_info WHERE id IN " +
            "<foreach collection='list' item='item' separator=',' open='(' close=')'>" +
            "#{item}" +
            "</foreach>"+
            "</script>")
    List<Map<Long,Long>> selectDeptIdListById(@Param("list") List<Long> deptIdList);
}
